<?php
class Pageley_Gateway_Database_BasicTransaction implements Pageley_Gateway_Database_Transaction {
	
    private $gateway;
    private $connection;
    private $id;
    private $singleStatement;
    
    public function __construct($gateway, $connection, $id, $singleStatement = false) {
        $this->gateway = $gateway;
        $this->connection = $connection;
        $this->id = $id;
        $this->singleStatement = $singleStatement;
    	if(Pageley_Log::isDebugEnabled($this)) {
			Pageley_Log::debug($this, "Connection " . $this->connection->getId() . " - Transaction " . $this->id . " started.");
		}
    }
    
    public function commit() {
        $this->connection->commit();
        $this->gateway->transactionComplete($this);
        $this->connection->close();
    	if(Pageley_Log::isDebugEnabled($this)) {
			Pageley_Log::debug($this, "Transaction " . $this->id . " committed.");
		}
    }
	
	public function rollback() {
        $this->connection->rollback();
        $this->gateway->transactionComplete($this);
        $this->connection->close();
    	if(Pageley_Log::isDebugEnabled($this)) {
			Pageley_Log::debug($this, "Transaction " . $this->id . " rolled back.");
		}
	}
    
    public function getConnection() {
        return $this->connection;
    }
    
    public function getSingleStatement() {
    	return $this->singleStatement;
    }
}